<?php
//Include the bootstrap
require_once("bootstrap.php");
 /* variables provided by 'bootstrap.php'
 	$basedir : absolute path to installation
 	$default : default database configuation object
 	$providers : auth source object as specified in providers.php
 	$Q : legacy configuration array
 */
		$body = "";
		$title = "";
		/*
		$menu = null;
		$footer = null;
		//and so on
		*/
if (isset($authenticated)) {
	if ($authenticated) {
		//continue.
		$modref = router_current_module($dblayer);
		if ($modref) {
				if (router_load_module($Q,$dblayer,$modref)) {
				$localTasks = "\$lTasks = {$modref}_local_tasks(\$Q,\$dblayer,\$providers,\$params);";
				$moduleTask = "\$page = {$modref}_task(\$Q,\$dblayer,\$providers,\$params);";
					$params['modref'] = $modref;
					$params['task'] = "default";
						if (isset($_GET{'task'})) {
							$params['task'] = GetParam("task","text","GET");
						}
							if (function_exists("{$modref}_local_tasks")) {
								eval($localTasks);
								if (isset($lTasks)) {
									if (count($lTasks)) {
										$localTaskHtml = "";
										$localTaskHtml .= "<div class='local-task-container'>\n";
										$themeparams = array();
										$themeparams['modref'] = $modref;
										$themeparams['profile'] = "local-task";
										foreach ($lTasks as $task) {
											$localTaskHtml .= theme($Q,$dblayer,$task,$themeparams);
										}
										$localTaskHtml .= "<div class='clearboth'></div>\n";
										$localTaskHtml .= "</div>\n";
									}
								}
							}
							if (function_exists("{$modref}_task")) {
								eval($moduleTask);
								if (isset($page)) {
									$title = $page['title'];
									$titleEval = "\$htmlTitle = {$modref}_title(\$Q,\$dblayer,\$params);";
									if (function_exists("{$modref}_title")) {
										eval($titleEval);
										//if (isset($htmlTitle)) {
											//$body .= $htmlTitle;
										//}
									}
									//if (isset($localTaskHtml)) {
										//$body .= $localTaskHtml;
									//}
									$body .= $page['body'];
								}
							}
				} else {
					//$body .= "<p>Could not load requested module.</p>\n";
				}// if/else load module
		} else {
			//$body .= "<p>No Modref.</p>\n";
		}
	} else {
		if (isset($auth)) {
			//display login form.
			$body .= $auth->login();
			$title = "You must login to access this system.\n";
		}
	}
} else {
	die("authenticated not set");
}
//load template and pass $body, $title et al to it.
//echo "<h1>".$title."</h1>\n";
//echo $body;
//$dblayer->query("SYSTEM","select * from variables where label = 'system_default_theme'");
//$thid = system_get_var($dblayer,"system_default_theme");
//$thid = default_theme($dblayer);
$thid = 1;
$params = array();
$params['title'] = $title;
$params['html-title'] = null;
if (isset($htmlTitle)) {
	$params['html-title'] = $htmlTitle;
}
$params['local-tasks-html'] = null;
if (isset($localTaskHtml)) {
	$params['local-tasks-html'] = $localTaskHtml;
}
$params['body'] = $body;
load_theme($Q,$dblayer,$thid,$params);
?>
